// 字典
// ES6中包含了一个Map类的实现，即这里所说的字典
// 不同于集合只在意 值
// 字典要存储的是 [键, 值]对

function Dictionary(){
	var items = {};

	this.has = function(key){
		return items.hasOwnProperty(key); // return key in items;
	}

	this.set = function(key, value){
		items[key] = value;
	}

	this.remove = function(key){
		if(this.has(key)){
			delete items[key];
			return true;
		}
		return false;
	}


	this.get = function(key){
		return this.has(key) ? items[key] : undefined;
	}

	this.values = function(){
		var values = [];
		for(var key in items){
			if(this.has(key)){
				values.push(items[key]);
			}
		}
		return values;
	}

	this.keys = function(){
		var keys = [];
		for(var key in items){
			if(this.has(key)){
				keys.push(key);
			}
		}
		return keys;
	}

	this.clear = function(){
		items = {};
	}

	this.size = function(){
		return this.keys().length;
	}

	this.getItems = function(){
		return items;
	}
}